package com.j.lemon.learn.thread.活跃性危险;

/**
 * @Author lijunjun
 * @Date 2019-04-02 16:31
 * @Description 死锁示例
 *
 * 其他还有：饥饿（优先级低，永远也无法执行）、活锁（活锁通常发生在处理事务消息的应用程序中：如果不能成功的处理某个消息，name消息处理机制将
 * 回滚整个事务，并将它重新放到队列的开头。这样就每次都发生回滚，每次都错误）、糟糕的响应性
 */
public class DeathLockDemo {
    private static final Object lock1 = new Object();
    private static final Object lock2 = new Object();

    public static void main(String[] args) {

        Thread thread1 = new Thread(() -> {
            synchronized (lock1){
                System.out.println("lock1 do");
                synchronized (lock2){
                    System.out.println("lock2 do");
                }
            }


        });


        Thread thread2 = new Thread(() -> {
            synchronized (lock2){
                System.out.println("lock2 do");
                synchronized (lock1){
                    System.out.println("lock1 do");
                }
            }
        });

        thread1.start();
        thread2.start();
    }
}
